package com.aigou.admin.controller;


import com.aigou.admin.entity.User;
import com.aigou.admin.service.UserService;
import com.aigou.admin.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/updateUser")
public class UpdateUserController extends HttpServlet {

    // 创建UserService的实例，用于后续调用用户相关服务
private UserService userService = new UserServiceImpl();

    /**
     * 这段代码是 FindUserController 类中的 doGet 方法。它的功能如下：
     * 接收 HTTP GET 请求：当客户端发送 GET 请求时，doGet 方法会被调用。
     * 转发请求到 doPost 方法：doGet 方法内部调用了 doPost 方法，将请求和响应对象传递给 doPost 方法处理。
     *
     */
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得用户id
        String userId = req.getParameter("userId");
        String userName = req.getParameter("userName");
        String userPwd = req.getParameter("userPwd");
        String userType = req.getParameter("userType");
        User user = new User(userId,userName,userPwd,Integer.valueOf(userType));
        //查询用户
        boolean rs = userService.update(user);
        //转换为JSON,通过流发送给客户端
        resp.getWriter().write(String.valueOf(rs));
    }



}
